Gomoku singlePlay judgment

SinglePlayForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Client
{
public partial class SinglePlayForm : Form
{
private const int rectSize = 33; //
private const int edgeCount = 15; //
private enum Horse { none = 0, BLACK, WHITE };
private Horse[,] board = new Horse[edgeCount, edgeCount];
private Horse nowPlayer = Horse.BLACK;
private bool playing = false;
public SinglePlayForm()
{
InitializeComponent();
}
private bool judge()
{
for(int i=0;i<edgeCount-4;i++)//
{
for(int j = 0; j < edgeCount; j++)
{
if (board[i, j] == nowPlayer && board[i + 1, j] == nowPlayer && board[i + 2, j] == nowPlayer && board[i + 3, j] == nowPlayer && board[i + 4, j] == nowPlayer)
return true;
}
}
for(int i=0;i<edgeCount;i++)//
{
for(int j = 4; j < edgeCount; j++)
{
if (board[i, j] == nowPlayer && board[i, j - 1] == nowPlayer && board[i, j - 2] == nowPlayer && board[i, j - 3] == nowPlayer && board[i, j - 4] == nowPlayer)
return true;
}
}
for(int i=0;i<edgeCount-4;i++)//y=x
{
for(int j=0;j<edgeCount-4;j++)
{
if (board[i, j] == nowPlayer && board[i + 1, j - 1] == nowPlayer && board[i + 2, j - 2] == nowPlayer && board[i + 3, j - 3] == nowPlayer && board[i + 4, j - 4] == nowPlayer)
return true;
}
}
for(int i=4; i<edgeCount;i++)//y=-x
{
for(int j = 0; j < edgeCount - 4; j++)
{
if (board[i, j] == nowPlayer && board[i - 1, j + 1] == nowPlayer && board[i - 2, j + 2] == nowPlayer && board[i - 3, j + 3] == nowPlayer && board[i - 4, j + 4] == nowPlayer)
return true;
}
}
return false;
}
private void refresh()
{
this.boardPicture.Refresh();
for(int i = 0; i < edgeCount; i++)
{
for(int j = 0; j < edgeCount; j++)
{
board[i, j] = Horse.none;
}
}
}
private void boardPicture_MouseDown(object sender, MouseEventArgs e)
{
if (!playing)
{
MessageBox.Show(" .");
return;
}
Graphics g = this.boardPicture.CreateGraphics();
int x = e.X / rectSize;
int y = e.Y / rectSize;
if (x < 0 || y < 0 || x >= edgeCount || y >= edgeCount)
{
MessageBox.Show(" .");
return;
}
if (board[x, y] != Horse.none) return;
board[x, y] = nowPlayer;
if (nowPlayer == Horse.BLACK)
{
SolidBrush brush = new SolidBrush(Color.Black);
g.FillEllipse(brush, x * rectSize, y * rectSize, rectSize, rectSize);
}
else
{
SolidBrush brush = new SolidBrush(Color.White);
g.FillEllipse(brush, x * rectSize, y * rectSize, rectSize, rectSize);
}
if (judge())
{
status.Text = nowPlayer.ToString() + " .";
playing = false;
playButton.Text = "";
}
else
{
nowPlayer = ((nowPlayer == Horse.BLACK) ? Horse.WHITE : Horse.BLACK);
status.Text = nowPlayer.ToString() + " .";
}
}
private void boardPicture_Paint(object sender, PaintEventArgs e)
{
Graphics gp = e.Graphics;
Color lineColor = Color.Black;
Pen p = new Pen(lineColor, 2);
gp.DrawLine(p, rectSize / 2, rectSize / 2, rectSize / 2, rectSize * edgeCount - rectSize / 2);
gp.DrawLine(p, rectSize / 2, rectSize / 2, rectSize * edgeCount - rectSize / 2, rectSize / 2);
gp.DrawLine(p, rectSize / 2, rectSize * edgeCount - rectSize / 2, rectSize * edgeCount - rectSize / 2, rectSize * edgeCount - rectSize / 2);
gp.DrawLine(p, rectSize * edgeCount - rectSize / 2, rectSize / 2, rectSize * edgeCount - rectSize / 2, rectSize * edgeCount - rectSize / 2);
p = new Pen(lineColor, 1);
for (int i = rectSize + rectSize / 2; i < rectSize * edgeCount - rectSize / 2; i += rectSize)
{
gp.DrawLine(p, rectSize / 2, i, rectSize * edgeCount - rectSize / 2, i);
gp.DrawLine(p, i, rectSize / 2, i, rectSize * edgeCount - rectSize / 2);
}
}
private void playButton_Click(object sender, EventArgs e)
{
if (!playing)
{
refresh();
playing = true;
playButton.Text = "";
status.Text = nowPlayer.ToString() + " .";
}
else
{
refresh();
status.Text = " .";
}
}
}
}